/*
 * @Description: ------------ fileDescription -----------
 * @Author: snows_l snows_l@163.com
 * @Date: 2024-10-30 17:29:56
 * @LastEditors: snows_l snows_l@163.com
 * @LastEditTime: 2024-10-30 20:04:51
 * @FilePath: /webseteUI/WebsiteUI/src/hooks/useKeyEventSubmit.ts
 */
import { onMounted, onUnmounted, ref } from 'vue';

export default function useKeyEventSubmit(callback) {
  const handleKeyupCallback = (e: KeyboardEvent) => {
    const key = e.key.toLowerCase();
    // 组合键
    const groupKeys = navigator.platform.match('Mac') ? e.metaKey : e.ctrlKey;
    if (key === 's' && groupKeys) {
      e.preventDefault();
      callback(true); // 调用回调函数 是否是组合键
    }
  };

  onMounted(() => {
    window.addEventListener('keydown', handleKeyupCallback);
  });

  onUnmounted(() => {
    window.removeEventListener('keydown', handleKeyupCallback);
  });
}
